package com.lingxu.module.collaborative.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lingxu.base.common.api.vo.Result;
import com.lingxu.base.common.util.DateUtil;
import com.lingxu.module.collaborative.entity.Collaborative;
import com.lingxu.module.collaborative.mapper.CollaborativeMapper;
import com.lingxu.module.collaborative.service.CollaborativeService;
import com.lingxu.module.collection.mapper.ReportMapper;
import com.lingxu.module.earlyWarn.entity.IssueManage;
import com.lingxu.module.info.entity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

/**
 * @Description: 协同编辑
 * @Author: jfx
 * @Date:   2023-04-10
 * @Version: V1.0.1
 */
@Service
public class CollaborativeServiceImpl extends ServiceImpl<CollaborativeMapper, Collaborative> implements CollaborativeService {

    @Autowired
    private CollaborativeMapper collaborativeMapper;

    @Override
    public int insertCollaborative(Collaborative collaborative) {
        return collaborativeMapper.insert(collaborative);
    }

    @Override
    public Result findCollaborativeList(Collaborative params) {
        try {
            // 定义输入日期时间字符串的格式
            SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            // 定义输出日期时间字符串的格式
            SimpleDateFormat outputFormat = new SimpleDateFormat("yyyyMMddHHmmss");
            // 将输入的日期时间字符串解析为 Date 对象
            if (null != params.getAskTimeStart() && "" != params.getAskTimeStart()){
                Date dateStart = inputFormat.parse(params.getAskTimeStart());
                params.setAskTimeStart(outputFormat.format(dateStart));
            }
            if (null != params.getAskTimeEnd() && "" != params.getAskTimeEnd()){
                Date dateEnd = inputFormat.parse(params.getAskTimeEnd());
                params.setAskTimeEnd(outputFormat.format(dateEnd));
            }
            Page<Collaborative> page = new Page<>(params.getPage(),params.getLimit());
            IPage<Collaborative> dataList = collaborativeMapper.findCollaborativeList(params,page);
            return Result.ok(dataList,"查询成功");
        }catch (Exception e){
            log.error("数据查询异常",e);
            return Result.error("查询异常");
        }
    }

    @Override
    public Result deleteCollaborativeById(String id) {
        collaborativeMapper.deleteById(id);
        return Result.ok("删除成功");
    }

    @Override
    public Result auditingById(Collaborative collaborative) {
        collaborativeMapper.updateById(collaborative);
        return Result.ok("审核成功");
    }
}
